package com.econ.powercloud.ems.service.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.econ.powercloud.ems.dal.entity.IotProductYkYtDit;
import com.econ.powercloud.ems.dal.mapper.IotProductYkYtDitMapper;
import com.mysql.cj.util.StringUtils;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author : zjf
 * @Description :
 * @Date : 2022/11/14 14:45
 * @Modified by : zjf
 */
@Repository
public class IotProductYkYtDitDAO extends ServiceImpl<IotProductYkYtDitMapper, IotProductYkYtDit> {

    /**
     * @param remoteType: 遥控遥调类型
     * @param search : 点号名称或标识
     * @return
     */
    public Page<IotProductYkYtDit> selectPageBySearch(String productKey, Integer remoteType, String search, Integer pageNo, Integer pageSize){
        LambdaQueryWrapper<IotProductYkYtDit> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(IotProductYkYtDit::getProductKey,productKey);
        lambdaQuery.eq(IotProductYkYtDit::getRemoteType,remoteType);
        lambdaQuery.and(!StringUtils.isNullOrEmpty(search),wrapper -> wrapper.like(IotProductYkYtDit::getDit, search).or().like(IotProductYkYtDit::getDitName, search));
        Page<IotProductYkYtDit> page = new Page<>(pageNo, pageSize);
        return this.baseMapper.selectPage(page,lambdaQuery);
    }

    public List<IotProductYkYtDit> selectListByProductKeysAndDits(List<String> productKeys,List<String> dits){
        LambdaQueryWrapper<IotProductYkYtDit> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.in(CollectionUtils.isNotEmpty(productKeys),IotProductYkYtDit::getProductKey,productKeys);
        lambdaQuery.in(CollectionUtils.isNotEmpty(dits),IotProductYkYtDit::getDit,dits);
        return this.baseMapper.selectList(lambdaQuery);
    }

}
